<?php
include '../common.php';
include '../common/header.php';
if (!$_SESSION['admin']) {
	header("location:../login.php",302);
}
$order = (int)$_GET['order'];
?>
<link href="<?=$website['public'];?>/admin/user.css" rel="stylesheet" type="text/css" />
<body>
    <div class="top">系统功能<i class="iconfont icon-arrowright">系统管理员</i></div>
    <div class="m5">
	    <div class="tabs">
	     	<ul class="tab_menu">
		     	<li><a href="user_name.php">管理员角色</a></li>
		     	<li class="current"><a href="user.php">系统管理员</a></li>
	     	</ul>
	     	<div class="tab_box">
				<div class="table-tip fn-clear">
					<div class="fn-left">
					<?php
						if ($_SESSION['user'] !== 3) {
						?><a href="add.php" class="button"><i class="iconfont icon-cjsqm"></i> 添加 </a>
						<?php
						}
						?>
						<a href="correct.php" class="button "><i class="iconfont icon-bianji"></i>修改密码</a>
					</div>
					<div class="fn-right">
						<form action="user.php" method="post">
							<input type="text" name="search" placeholder="请输入关键词搜索" autocomplete="off" class="input">
							<input type="submit" value="搜索" class="search">
						</form>
					</div>
				</div>
				<table class="table">
					<thead>
					<tr>
						<th class="table_th"><?php
						if ($order) {
						?>
							<a href="user.php?order=0">降序</a>
						<?php
						}else{
						?>
							<a href="user.php?order=1">升序</a>
						<?php
						}
						?></th>
						<th class="table_th">用户名</th>
						<th class="table_th">角色</th>
						<th class="table_th">手机</th>
						<th>邮箱</th>
						<th class="table_th">最后登录时间</th>
						<th class="table_th">操作</th>
					</tr>
					<?php
					$search = trim($_POST['search']);
					if (empty($search)) {
						if ($order == '1') {
							$sql = "SELECT * FROM user ORDER BY id ASC";
						}else{
							$sql = "SELECT * FROM user ORDER BY id DESC";
						}
					}else{
						$sql  = "SELECT * FROM user WHERE name = '{$search}'";
					}
					$row = select($sql,$DB);
					foreach ($row as $key => $value) {
					?>
					<tr>
						<td><?php echo $value['id']; ?></td>
						<td><?php echo $value['name']; ?></td>
						<td><?php
						if (trim($value['user']) === '1') {
							echo "超级管理员";
						}elseif (trim($value['user']) === '2') {
							echo "系统管理员";
						}elseif (trim($value['user']) === '3') {
							echo "普通管理员";
						}
						 ?></td>
						<td><?php echo $value['phone']; ?></td>
						<td><?php echo $value['email']; ?></td>
						<td><?php echo date('Y-m-d H:i:s',$value['hour'])?></td>
						<?php
						if ($_SESSION['user'] === 1) {
							if (trim($value['user']) === '1') {
						?>
							<td></td>
						<?php }else{ ?>
							<td>
							<a href="delete.php?delete=<?php echo $value['id']?>"><i class="iconfont icon-shanchu"></i></a>
							<a href="power.php?power=<?php echo $value['id']?>"><i class="iconfont icon-bianji"></i></a>
							</td>
						<?php
							}
						}elseif ($_SESSION['user'] === 2) {
							if (trim($value['user']) === '3') {
						?>
						<td><a href="delete.php?delete=<?php echo $value['id']?>"><i class="iconfont icon-shanchu"></i></a></td>
						<?php }else{ ?>
							<td></td>
						<?php }
						}else{ ?>
						<td></td>
					<?php } ?>
					</tr>
				<?php
				}
				?>
					</thead>	
				</table>
	     	</div>
	    </div>
	</div>
</body>
</html>